<template>

	<div style="width: 1100px;">

		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{  path: '/adminHome' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item><a href="/adminHome">业务审核</a></el-breadcrumb-item>
			<el-breadcrumb-item>广告审核</el-breadcrumb-item>
		</el-breadcrumb>

		<el-card class="box-card" style="width: 1200px; margin-top: 1.875rem; margin-right: -100px;">
			<div style="float: left; margin-top:1.875rem ;">
				<el-input type="txte" v-model="queryInfo.username" placeholder="请输入内容"
					style="width: 200px;height: 50px;"></el-input>
				<el-button type="primary" icon="el-icon-search" @click="queryAll">查询</el-button>
			</div>


			<el-table :data="tableData" border style="width: 100%">

				<el-table-column prop="advertName" label="广告名称">
				</el-table-column>
				<el-table-column prop="projectId" label="发起人">
				</el-table-column>
				<el-table-column prop="advertImg" label="图片">
					<template slot-scope="scope">
						<el-image style="width: 50px; height: 50px"
							:src="'http://localhost:8080/vueload?filename='+scope.row.advertImg" :fit="fit">
						</el-image>

					</template>
				</el-table-column>
				<el-table-column prop="beginTime" label="开始时间">
				</el-table-column>
				<el-table-column prop="endTime" label="结束时间">
				</el-table-column>
				</el-table-column>
				<el-table-column prop="istg" label="状态">
					<template slot-scope="scope">
						<span v-if="scope.row.istg==1">待审核</span>
						<span v-if="scope.row.istg==2">通过审核</span>
						<span v-if="scope.row.istg==3">审核失败</span>
					</template>
				</el-table-column>

				<el-table-column label="操作" width="200px">
					<template slot-scope="scope">
						<el-tooltip class="item" effect="dark" content="通过" placement="top-start">
							<el-button type="success" icon="el-icon-finished"
								@click.once="tongguo(scope.row.advertId,2)" v-show="scope.row.istg==1">
							</el-button>
						</el-tooltip>
						<el-tooltip class="item" effect="dark" content="拒绝" placement="top-start">
							<el-button type="success" icon="el-icon-s-release"
								@click.once="tongguo(scope.row.advertId,3)" v-show="scope.row.istg==1">
							</el-button>
						</el-tooltip>
						<el-tooltip class="item" effect="dark" content="删除" placement="top-start">
							<el-button type="success" icon="el-icon-delete" @click="deleteG(scope.row.advertId)" v-show="scope.row.istg==3">
							</el-button>
						</el-tooltip>




					</template>

				</el-table-column>
			</el-table>


			<!-- 分页 -->

			<el-pagination @current-change="handleCurrentChange" :current-page="queryInfo.pageNum"
				:page-sizes="[1, 4, 8, 10]" :page-size="3" layout="total, prev, pager, next, jumper" :total="total">
			</el-pagination>


		</el-card>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				tableData: [],
				queryInfo: {
					pageNum: 1,
					username: '',
					total: 0
				}

			}
		},
		methods: {
			//删除广告
			 deleteG(id) {

				this.$confirm('删除广告?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(async() => {
					var res = await this.$http.get('deleteAdvert?advertId=' + id)
					if (res.data.code == 200) {
						this.queryAll()
						this.$message("删除成功")
					} else {
						this.$message.error("删除失败")
					}
					
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});

			},

			// 通过审核
			async tongguo(id, istg) {
				alert(istg)
				var param = new URLSearchParams();
				param.append('advertId', id)
				param.append('istg', istg)
				var res = await this.$http.post('updateAdvert', param);
				if (res.data.code == 200) {
					this.$message(res.data.message)
					this.queryAll()
				} else {
					this.$message.error(res.data.message)
				}

			},


			//查询全部
			async queryAll() {

				var param = new URLSearchParams();
				param.append('pageNum', this.queryInfo.pageNum)
				param.append('advertName', this.queryInfo.username)
				var res = await this.$http.post('/queryAdvertAll', param)
				this.tableData = res.data.data.list
				this.total = res.data.data.total
			},
			// 页码大小
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
			},
			// 页码变动
			handleCurrentChange(val) {
				this.queryInfo.pageNum = val;
				this.queryAll();
			}

		},
		async mounted() {
			this.queryAll()

		}
	}
</script>

<style>
</style>
